Sub InsertDataToSheets()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim i As Integer
    Dim totalSheets As Integer
    Dim avgScore As Double
    Dim sumScore As Double
    Dim scoreCount As Integer

    Set wb = ThisWorkbook
    totalSheets = wb.Sheets.Count

    ' 첫 번째 시트에 부서 이름 입력
    Set ws = wb.Sheets(1)
    ws.Range("B6:B9").Value = wb.Sheets(2).Name
    ws.Range("C6:C9").ClearContents

    ' 두 번째부터 마지막 시트까지
    For i = 2 To totalSheets
        ' 평균 점수 계산
        sumScore = 0
        scoreCount = 0
        For Each cell In wb.Sheets(i).Range("D5:D" & wb.Sheets(i).Cells(Rows.Count, 4).End(xlUp).Row)
            If IsNumeric(cell.Value) Then
                sumScore = sumScore + cell.Value
                scoreCount = scoreCount + 1
            End If
        Next cell
        If scoreCount > 0 Then
            avgScore = sumScore / scoreCount
        Else
            avgScore = 0
        End If

        ' 부서 이름 및 평균 점수 입력
        ws.Cells(5 + i, 2).Value = wb.Sheets(i).Name
        ws.Cells(5 + i, 3).Value = avgScore
    Next i
End Sub
